<?php
/**
 * CreateTime: 2022/5/16 15:50
 */

namespace App\Tools\Sms;


use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;

use App\Consts\SMSConsts\AliSmsConsts;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
class BaseAliSms
{

    /**
     * 使用AK&SK初始化账号Client
     */
    public static function createClient(){
        $config = new Config([
            // 您的AccessKey ID
            "accessKeyId" => AliSmsConsts::AccessKeyID,
            // 您的AccessKey Secret
            "accessKeySecret" => AliSmsConsts::AccessKeySecret
        ]);
        // 访问的域名
        $config->endpoint = "dysmsapi.aliyuncs.com";
        return new Dysmsapi($config);
    }

    /**
     *
     * @return void
     */
    public static function sendSMS($signName,$templateCode,$phoneNumbers,$templateParam){
        $client = self::createClient();
        $sendSmsRequest = new SendSmsRequest([
            "signName" => $signName,
            "templateCode" => $templateCode,
            "phoneNumbers" => $phoneNumbers,
            "templateParam" => $templateParam
        ]);
        // 复制代码运行请自行打印 API 的返回值
        $res = $client->sendSms($sendSmsRequest);
        dd($res);
    }
}